/*
 * @Description:返回 内部带返回Map可用在函数多返回类型
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2022-11-29 20:46:28
 * @LastEditors: wiz
 * @LastEditTime: 2023-11-09 16:01:16
 */
export class T_return<T = any> {
  // 错误消息
  private _err!: string;

  // 返回对象，用在函数返回时多个对象
  public returnData?: Map<string, T>;

  constructor(errmsg: string = '') {
    this._err = errmsg;
    this.returnData = new Map();
  }

  public set errmsg(errmsg: string) {
    this._err = errmsg;
  }

  public get errmsg(): string {
    return this._err;
  }

  // 设置err 消息 输出T_error
  public error(errmsg: string): T_return<T> {
    this._err = errmsg;
    return this;
  }

  public isErr(): boolean {
    return !!this._err;
  }

  public getReturnData(key: string): T {
    return this.returnData.get(key);
  }

  public getReturnDataMap(): Map<string, T> {
    return this.returnData;
  }

  public setReturnData(key: string, value: T) {
    this.returnData.set(key, value);
  }
}

export interface I_return<T = any> extends T_return<T> {}
